package model.service;

import java.math.BigDecimal;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import model.dao.ReserVationDao;
import model.vo.mycinema.MyMovieInfoVO;
import model.vo.reservation.PaymentMethodInfoVO;
import model.vo.reservation.ReservationVO;
import model.vo.reservation.TimeTableVO;
import model.vo.theater.LocalInfoVO;

public class ReserVationService {
	private ReserVationDao reserVationDao;

	public void setReserVationDao(ReserVationDao reserVationDao) {
		this.reserVationDao = reserVationDao;
	}

	public ArrayList<HashMap> getScreeningMovieList() throws SQLException {
		return reserVationDao.getScreeningMovieList();
		
	}

	public ArrayList<LocalInfoVO> getLocalListByMovieNo(int movie_no) throws SQLException {
		return reserVationDao.getLocalListByMovieNo(movie_no);
	}

	public ArrayList<HashMap> getTheaterListByLocalAndMovie(HashMap map) throws SQLException {
		return reserVationDao.getTheaterListByLocalAndMovie(map);
	}

	public ArrayList<HashMap> getTimeTableList(TimeTableVO ttVO) throws SQLException {
		
		return reserVationDao.getTimeTableList(ttVO);
	}

	public ArrayList<PaymentMethodInfoVO> getPaymentMethodInfo() throws SQLException {
		
		return reserVationDao.getPaymentMethodInfo();
	}

	public void setReservationInfo(ReservationVO rVO) throws SQLException {
		System.out.println("ReserVationService....setReservationInfo");
		reserVationDao.setReservationInfo(rVO);
		ArrayList<HashMap> list =reserVationDao.getReservationInfo(rVO);
		System.out.println(list.toString());
		int res_no=Integer.parseInt(((BigDecimal) list.get(0).get("RES_NO")).toString());		
		String booking_date=  (String) list.get(0).get("BOOKING_DATE");
		System.out.println(booking_date);
		rVO.setRes_no(res_no);
		rVO.setBooking_date(booking_date);	
		reserVationDao.setReservationMyMovieInfo(rVO);
		
	}
	public ArrayList<HashMap> getReservationConfirm(int timetable_no) throws SQLException {
		return reserVationDao.getReservationConfirm(timetable_no);
	}
	public int getMovieGradeByMovieNo(int movie_no) throws SQLException {
		return reserVationDao.getMovieGradeByMovieNo(movie_no);
	}

	public String getMovieTitle(int movie_no) throws SQLException {
		return reserVationDao.getMovieTitle(movie_no);
	}

	public ArrayList<String> getConfirmedSeat(int timetable_no) throws SQLException {
		return (ArrayList<String>)reserVationDao.getConfirmedSeat(timetable_no);
	}

	public ArrayList<Map> getReservationList(int member_no) {
		ArrayList<Map> list = null;
		try {
			list = reserVationDao.getReservationList(member_no);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return list;
	}

	public void reservationDelete(ArrayList<String> list) {
		for(String res_no : list){
			ReservationVO rvo;
			try {
				rvo = reserVationDao.getReservationInfo(res_no);
				reserVationDao.insertMyMovieInfo(rvo);
				reserVationDao.deleteReservation(res_no);
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
}	
